/*
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-03-22 12:12:49
 * @LastEditTime: 2022-03-22 12:23:36
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 重写ElementUI的Message
 * @FilePath: \vue3-element-plus-web\src\utils\DonMessage.js
 * @Copyright 版权声明
 */
import { ElMessage } from 'element-plus'

// 为了实现Class的私有属性
const showMessage = Symbol('showMessage')

/**
 *  @description 重写ElementUI的Message
 *  single默认值true，因为项目需求，默认只弹出一个，可以根据实际需要设置
 */
export class DonMessage {
  success(options, single = true) {
    this[showMessage]('success', options, single)
  }
  warning(options, single = true) {
    this[showMessage]('warning', options, single)
  }
  info(options, single = true) {
    this[showMessage]('info', options, single)
  }
  error(options, single = true) {
    this[showMessage]('error', options, single)
  }

  [showMessage](type, options, single) {
    if (single) {
      // 判断是否已存在Message
      if (document.getElementsByClassName('el-message').length === 0) {
        ElMessage[type](options)
      }
    } else {
      ElMessage[type](options)
    }
  }
}

// 命名根据需要，DonMessage只是在文章中使用
// Vue.prototype.$message = new DonMessage()
